package com.baibei.ebec.user.messagenotice;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baibei.basic.BasicRecyclerViewAdapter;
import com.baibei.ebec.user.R;
import com.baibei.model.MessageInfo;
import com.baibei.model.MsgNoticeInfo;
import com.baibei.widget.ExpandableTextView;

import java.util.ArrayList;
import java.util.List;

public class MessageNoticeAdapter extends RecyclerView.Adapter<MessageNoticeAdapter.ViewHolder>  {

    private ArrayList<MsgNoticeInfo> datas = null;
    public MessageNoticeAdapter(ArrayList<MsgNoticeInfo> list){
        this.datas = list;
    }

    @Override
    public MessageNoticeAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_msgnotice, null);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(MessageNoticeAdapter.ViewHolder viewHolder, int i) {
        MsgNoticeInfo msgNoticeInfo = datas.get(i);
        viewHolder.tv_content.setText(msgNoticeInfo.getMessage());
        viewHolder.tv_date.setText(msgNoticeInfo.getTime());
        viewHolder.tv_title.setText(msgNoticeInfo.getTitle());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void setInfos(List<MsgNoticeInfo> list) {
        this.datas.clear();
        this.datas.addAll(list);
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private final TextView tv_title;
        private final TextView tv_date;
        private final ExpandableTextView tv_content;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_date = itemView.findViewById(R.id.tv_date);
            tv_content = itemView.findViewById(R.id.expand_text_view);
        }
    }
}
